package org.caowei.samples.dao;

import java.util.List;

import org.caowei.samples.model.ExamTest;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class ExamTestDAO extends BaseHibernateDAO<ExamTest> implements IExamTestDAO {

	@Override
	public List<ExamTest> findAllExamTests() {
//		return this.loadAll();
		String hql = "FROM ExamTest";
		List<ExamTest> examTestlist =this.find(hql);
		return examTestlist;
	}

	@Override
	public ExamTest getExamTestById(int id) {
		return this.get(id);
	}

	@Override
	public void createExamTest(ExamTest ExamTest) throws Exception {
		if (ExamTest != null) {
			this.save(ExamTest);
		}
	}

	@Override
	public void editExamTest(ExamTest ExamTest) throws Exception {
		if (ExamTest != null) {
			this.update(ExamTest);
		}
	}

	@Override
	public void deleteExamTest(int id) throws Exception {
		ExamTest exsitsExamTest = this.get(id);
		if (exsitsExamTest != null) {
			this.delete(exsitsExamTest);
		}
	}

	@Override
	public List<ExamTest> findExamTestBySubjectId(int subId) {
		String hql = " FROM ExamTest as et where et.subject1.subId = "+ subId +"";
		return find(hql);
	}

}
